package com.example.blogserver.controller;

import com.example.blogserver.pojo.User;
import com.example.blogserver.service.ListService;
import com.example.blogserver.service.UpdateService;
import com.example.blogserver.a_utils.ResponseBodyMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@SuppressWarnings({"all"})
@RestController
@RequestMapping("/update")
public class UpdateController {
    @Autowired
    private UpdateService updateService;

    @Autowired
    private ListService listService;

    /**
     * 获取用户个人信息
     */
    @RequestMapping("/myMse")
    public ResponseBodyMessage<User> MyCard(HttpServletRequest request){
        return listService.queryByAccount(request);
    }

    /**
     * 修改个人信息
     */
    @RequestMapping("/uploadMy")
    public ResponseBodyMessage<Boolean> updateMessage(HttpServletRequest request,
                                                      @RequestParam String Uname,
                                                      @RequestParam String Usig,
                                                      @RequestParam String Upas1,
                                                      @RequestParam String UoldPas,
                                                      @RequestParam String Upas2,
                                                      @RequestParam String Uemail,
                                                      @RequestParam String Ucode,
                                                      @RequestParam String Ugitee){
        return updateService.updateMessage(request,Uname,Usig,Upas1,UoldPas,Upas2,Ucode,Uemail,Ugitee);
    }


    /**
     * 上传头像
     */
    @RequestMapping("/uploadMyPhoto")
    @Transactional
    public ResponseBodyMessage<Boolean> uploadMyPhoto(@RequestPart("myimg") MultipartFile file, HttpServletRequest request){
        return updateService.uploadMyPhoto(file,request);
    }
}
